package cn.ac.iie.ulss.dataredistribution.tools;

import cn.ac.iie.ulss.dataredistribution.consistenthashing.HashCodeNodeLocator;
import cn.ac.iie.ulss.dataredistribution.consistenthashing.MD5NodeLocator;
import cn.ac.iie.ulss.dataredistribution.consistenthashing.NodeLocator;
import java.util.ArrayList;
import org.apache.log4j.PropertyConfigurator;

/**
 *
 * @author evan yang
 * @date: 2014-10-15
 */
public class Rule {

    private String table = null;
    private String urlEnd = null;
    ArrayList<HNode> nodes = null;
    private String keywords = null;
    private NodeLocator nodelocator = null;
    private String partType = null;
    static org.apache.log4j.Logger logger = null;

    static {
        PropertyConfigurator.configure("log4j.properties");
        logger = org.apache.log4j.Logger.getLogger(Rule.class.getName());
    }

    public Rule(String topic,
            String endUrl ,
            ArrayList<HNode> nodes,
            String keywords,
            NodeLocator nodelocator,
            String partType) {
        this.table = topic;
        this.urlEnd = endUrl;
        this.nodes = nodes;
        this.keywords = keywords;
        this.nodelocator = nodelocator;
        this.partType = partType;
    }

    public synchronized String getTable() {
        return table;
    }

    public synchronized String getEndUrl() {
        return urlEnd;
    }
    
    public synchronized ArrayList getNodes() {
        return nodes;
    }

    public synchronized String getKeywords() {
        return keywords;
    }

    public synchronized void setKeywords(String keywords) {
        this.keywords = keywords;
    }

    public synchronized NodeLocator getNodelocator() {
        return nodelocator;
    }

    public synchronized void setNodelocator(MD5NodeLocator nodelocator) {
        this.nodelocator = nodelocator;
    }

    public synchronized String getPartType() {
        return partType;
    }

    public synchronized void setPartType(String partType) {
        this.partType = partType;
    }

    /**
     *
     * update rule's nodeUrls , nodelocator , keywords , partType
     */
    public synchronized void changerule(ArrayList<HNode> nurl,HashCodeNodeLocator nodelocator, String keywords, String partType) {
        this.nodes = nurl;
        this.nodelocator = nodelocator;
        this.keywords = keywords;
        this.partType = partType;
    }
}
